<?php
/**
 * QQAS - share your knowledge to the world!
 *
 * @author		xiaochong0302 <xiaochong0302@gmail.com>
 * @copyright	Copyright (c) 2011, Koogua Studio.
 * @license		http://www.qqas.org/user_guide/license.html
 * @link		http://www.qqas.org
 * @since		Version 1.0
 * @filesource
 */


class CommunityStatsWidget extends Widget
{

    /**
     *
     * @param $data = array('expire' => 30);
     */
    public function render($data)
    {

        $expire = empty($data['expire']) ? 30 * 60 : intval($data['expire'] * 60);
        $name = 'cache_community_stats';
        $stats = S($name);

        if(empty($stats))
        {
            $User = M('User');
            $Question = M('Question');
            $Answer = M('Answer');
            $Comment = M('Comment');

            $map = array('user_group' => array('neq', 4));
            $userCount = $User->where($map)->count();

            $map = array('is_visible' => 1);
            $questionCount = $Question->where($map)->count();
            $answerCount = $Question->where($map)->count();
            $commentCount = $Comment->where($map)->count();

            $stats = array(
                'user_count'     => intval($userCount),
                'question_count' => intval($questionCount),
                'answer_count'   => intval($answerCount),
                'comment_count'  => intval($commentCount),
            );
            S($name, $stats, $expire);
        }
        $data['stats'] = $stats;

        $tplFile = TEMPLATE_PATH .'/Home/Widget_communityStats.html';
        $content = $this->renderFile($tplFile, $data);
        return $content;
    }

}

/* End of file HelpTipsWidget.class.php */
/* Location: ./App/Lib/Widget/HelpTipsWidget.class.php */
